package com.itboye.allshengmedical.sci.packet.resp;

import android.util.Log;

public class GetTempRespPacket extends BaseRespPacket {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7418006245135996432L;
	BaseRespPacket packet = new BaseRespPacket();

	public GetTempRespPacket(BaseRespPacket packet) {
		this.clone(packet);
		this.packet = packet;
		this.setExpectDataLength(0x0A);
	}

	private byte get(int index) {
		return packet.getContent()[index];
	}

	public String ModeOne() {

		if (isLegalContent()) {
			int temptwo = get(2);
			int tempThree = get(3);
			if (get(1) == 0x01) {
				if (tempThree < 0) {
					tempThree = tempThree + 256;
				}
				if (temptwo < 0) {
					temptwo = temptwo + 256;
				}
				return "-" + (temptwo * 256 + tempThree) / 10.0;
			} else {
				if (tempThree < 0) {
					tempThree = tempThree + 256;
				}
				if (temptwo < 0) {
					temptwo = temptwo + 256;
				}

				return (temptwo * 256 + tempThree) / 10.0 + "";
			}
		}
		return "错误数据";
	}

	public String ModeTwo() {
		int temptwo = get(5);
		int tempThree = get(6);
		if (get(4) == 1) {
			if (tempThree < 0) {
				tempThree = tempThree + 256;
			}
			if (temptwo < 0) {
				temptwo = temptwo + 256;
			}
			return "-" + (temptwo * 256 + tempThree) / 10.0;
		} else {
			if (tempThree < 0) {
				tempThree = tempThree + 256;
			}
			if (temptwo < 0) {
				temptwo = temptwo + 256;
			}

			return (temptwo * 256 + tempThree) / 10.0 + "";
		}
	}

	public String ModeThree() {
		int temptwo = get(8);
		int tempThree = get(9);
		if (get(7) == 1) {
			if (tempThree < 0) {
				tempThree = tempThree + 256;
			}
			if (temptwo < 0) {
				temptwo = temptwo + 256;
			}
			return "-" + (temptwo * 256 + tempThree) / 10.0;
		} else {
			if (tempThree < 0) {
				tempThree = tempThree + 256;
			}
			if (temptwo < 0) {
				temptwo = temptwo + 256;
			}

			return (temptwo * 256 + tempThree) / 10.0 + "";
		}
	}

	public String ModeOneTemp() {
		String string = null;
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append("模块1=");
		// if (isLegalContent() && this.getContent(1) == 0x00) {
		if (this.getContent(1) == 0x00) {
			stringBuffer.append("");
		} else {
			stringBuffer.append("-");
		}
		StringBuffer modeOneBuffer = new StringBuffer();
		modeOneBuffer.append(this.getContent(2));
		modeOneBuffer.append(this.getContent(3));
		stringBuffer.append((Integer.parseInt(modeOneBuffer.toString(), 16))
				+ "");
		stringBuffer.append(",模块2=");
		if (this.getContent(4) == 0x00) {
			stringBuffer.append("");
		} else {
			stringBuffer.append("-");
		}
		StringBuffer ModeTwoBuffer = new StringBuffer();
		ModeTwoBuffer.append(this.getContent(5));
		ModeTwoBuffer.append(this.getContent(6));
		stringBuffer.append((Integer.parseInt(ModeTwoBuffer.toString(), 16))
				+ "");
		stringBuffer.append(",上盖温度=");
		if (this.getContent(7) == 0x00) {
		} else {
			stringBuffer.append("-");
		}
		StringBuffer ModeThreeBuffer = new StringBuffer();
		ModeThreeBuffer.append(this.getContent(8));
		ModeThreeBuffer.append(this.getContent(9));
		stringBuffer.append((Integer.parseInt(ModeThreeBuffer.toString(), 16))
				+ "");
		string = stringBuffer.toString();
		stringBuffer = null;
		modeOneBuffer = null;
		ModeTwoBuffer = null;
		ModeThreeBuffer = null;
		return string;
	}
}
